/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFGana
  \brief The main frame of the ETFAna offline GUI
  Currently there is only a matrix of buttons each of which calls explicitly a
  shell command which opens another termianl and executes a certain ROOT macro.
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2024-05-06
  \date 2024-05-07 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2024-05-06   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFGana_h
#define ETFGana_h

#include <vector>
#include <string>
#include <map>
#include <TGFrame.h>

using std::vector;
using std::string;
using std::map;

class TGTextEntry;
class ETFGanaPre;

struct bt_t{
  TGTextButton *button;
  string macro;
  bool hasClicked;
};

class ETFGana : public TGMainFrame{
public:
	ETFGana(const string &rtf, int w = 1000, int h = 625);
	virtual ~ETFGana();

  virtual void Initialize(); ///< creaet all the graphical objects
  virtual void Configure(); ///< visualize all the graphical objects
  virtual void CloseWindow() override;
  
  virtual void AddButtonGroup(const string &title);
  /// \param cat: button category, e.g., "DAQ", "DET", "TRK" or "PID"
  /// \param mac: the macro in (for the time being) config/apr2023/cmd, e.g, dr.C
  /// \param tip: the descriptive tip to the button's function
  virtual void AddButton(const string &cat, const string &mac, const string &name,
    const string &tip = "");
  ///< react to button with the id
  virtual void ButtonReact(int id = -1);
  virtual void SetROOTFile(const string &rtf);
  
  virtual void ActivatePostAna(); ///< activate buttons in fvvB
  virtual void DeactivatePostAna(); //< deactivate buttons in fvvB
  void ActivateStopButton();

  void Stop(); ///< stop the ana process
  void Logo(); ///< show the logo
  void About(){ Logo(); } ///< show the logo
  ETFGanaPre *GetGanaPre() const{ return fGanaPre; }
  static unsigned long magenta(){ return kGanaMagenta; }
  static unsigned long green(){ return kGanaGreen; }
  static unsigned long red(){ return kGanaRed; }
  static unsigned long white(){ return kGanaWhite; }
  static unsigned long yellow(){ return kGanaYellow; }
  static unsigned long pink(){ return kGanaPink; }
  static unsigned long cyan(){ return kGanaCyan; }
  static unsigned long purple(){ return kGanaPurple; }
  static unsigned long blue(){ return kGanaBlue; }

	ClassDefOverride(ETFGana, 0);

protected:
  static unsigned long kGanaMagenta, kGanaGreen, kGanaRed, kGanaWhite,
    kGanaYellow, kGanaPink, kGanaCyan, kGanaPurple, kGanaBlue;

  TGCompositeFrame *fHBtn, *fPad; ///< for menu bar and button matrix container
  TGTextButton *fExit, *fStop, *fLogo;
  vector<TGGroupFrame *> fvGF;
  TGLayoutHints *fLF, *fLB; ///< layouts for group frames and buttons in them
  vector<vector<TGTextButton *> *> fvvB; ///< button array for each button group
  map<int, bt_t> fMap; ///< map<button_id, button_info>

  string fROOTFile; ///< the rootfile generated from the raw data files
  int fUserOpt; ///< the return status of user selection from dialog
  unsigned fWidth, fHeight;

  ETFGanaPre *fGanaPre; ///< decoder and analyzer of the raw data files
};

#endif
